//
//  DataBase.m
//  iNews
//
//  Created by lanou3g on 14-12-15.
//  Copyright (c) 2014年 张在青. All rights reserved.
//

#import "DataBase.h"
#import "FMDatabase.h"
#import "FMResultSet.h"

//#import "FMDatabasePool.h"
//#import "FMDatabaseAdditions.h"

@implementation DataBase



//获取存取数据的文件沙盒地址
+(NSString *)databaseFilePath
{
    NSArray *filePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) ;
    
    NSString *documentPath = [filePath objectAtIndex:0];
    
    NSLog(@"%@",filePath);
    
    NSString *dbFilePath = [documentPath stringByAppendingPathComponent:@"MP3.sqlite"];
  
    return dbFilePath;
}



//创建表
+(void)creatTable
{
    FMDatabase *db = [[FMDatabase databaseWithPath:[self databaseFilePath]] autorelease];
    
    if (!db) {
        [self  databaseFilePath];
    }
    if (![db open]) {
        NSLog(@"数据库打开失败");
        return;
    }else
    {
    //为数据库设置缓存,提高查询效率
    [db setShouldCacheStatements:YES];
    //判断数据库中是否已经存在这个表,如果不存在就创建这个表
    BOOL flag = [db executeUpdate:@"CREATE TABLE mytable(title TEXT , mp3url TEXT)"];
    if (flag) {
        NSLog(@"创建成功!");
    }else
    {
        NSLog(@"创建失败!");
    }
    }
    
}



@end
